﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DebitNote.aspx.cs" Culture="en-GB" Inherits="Main_Reports_Accounts_AccountBooks_DebitNote" %>
<%@ Register Src="~/User Controls/PageHeading.ascx" TagName="Heading" TagPrefix="acc" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="../../../../Styles/accounts.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        function Validation() {
            var flag = true;
            var txtFromdate = document.getElementById("txtFromDate").id;
            var txtTodate = document.getElementById("txtToDate").id;
            if (document.getElementById("txtFromDate").value == '') {
                alert('Specify From date');
                flag = false;
            }
            else if (document.getElementById("txtToDate").value == '') {
                alert('Specify To date');
                flag = false;
            }
            else {
                if (isDate(txtFromdate) && isDate(txtTodate)) {
                    var dateArray = new Array();
                    dateArray = document.getElementById("txtFromDate").value.split("/");
                    var day1 = dateArray[0];
                    var month1 = dateArray[1];
                    var year1 = dateArray[2];
                    dateArray = document.getElementById("txtToDate").value.split("/");
                    var day2 = dateArray[0];
                    var month2 = dateArray[2];
                    var year2 = dateArray[2];

                    if (day1.length < 2) {
                        day1 = '0' + day1;
                    }
                    if (month1.length < 2) {
                        month1 = '0' + month1;
                    }
                    if (day2.length < 2) {
                        day2 = '0' + day2;
                    }
                    if (month2.length < 2) {
                        month2 = '0' + month2;
                    }
                    var date1 = new Date(year1, month1 - 1, day1);
                    var date2 = new Date(year2, month2 - 1, day2);
                    if (date1 > date2) {
                        alert('Date Could Not be less than From Date');
                        document.getElementById(txtFromdate).focus();
                        flag = false;

                    }
                }
                else {
                    flag = false;
                }
            }
            return flag;
        }
        function isDate(txtDateId) {
            // date length should be 10 characters - no more, no less            
            var Ctrl = document.getElementById(txtDateId);
            var txtDate = Ctrl.value;
            var flag = true;

            // extract day, month and year from the txtDate string
            // expected format is dd/mm/yyyy
            var day = '';
            var month = '';
            var year = '';
            var dateArray = new Array();
            var count = 0;
            for (var j = 0; j < txtDate.length; j++) {
                var chara = txtDate.charAt(j);
                if (chara == '/') {
                    count += 1;
                }
            }
            if (count != 2) {
                alert('Invalid date !');
                return false;
            }
            dateArray = txtDate.split("/");


            day = dateArray[0];
            month = dateArray[1];
            year = dateArray[2];


            if (year.length != 4) {
                alert('Invalid date !');
                return false;
            }
            var finYear = document.getElementById("hidFinyear").value;
            if (month >= 4 && year != parseInt(finYear)) {
                alert('Date Should be between 01/04/' + finYear + ' and 31/03/' + (parseInt(finYear) + 1));
                return false;
            }
            else if (month < 4 && year != (parseInt(finYear) + 1)) {
                alert('Date Should be between 01/04/' + finYear + ' and 31/03/' + (parseInt(finYear) + 1));
                return false;
            }



            if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
                if (day > 31) {
                    alert('Date Should not be Greater than 31');
                    Ctrl.focus();
                    flag = false;
                }
            }
            //for have only 30 day
            else if (month == 4 || month == 6 || month == 9 || month == 11) {
                if (day > 30) {
                    alert('Date Should not be Greater than 30');
                    Ctrl.focus();
                    flag = false;
                }
            }
            //for Febuary 
            else if (month == 2) {
                var leap = year % 4;
                if (leap == 0) {
                    if (day > 29) {
                        alert('february have only 29 days');
                        Ctrl.focus();
                        flag = false;
                    }
                }
                else {
                    if (day > 28) {
                        alert('february have only 28 days');
                        Ctrl.focus();
                        flag = false;
                    }
                }
            }
            else if (month > 12) {
                alert('Invalid Date');
                Ctrl.focus();
                flag = false;
            }
            // otherwise return true
            return flag;
        }



        function printPartOfPage() {
        
           
            var printDiv = document.getElementById("divPrint").innerHTML;
            var windowUrl = 'about:blank';
            var uniqueName = new Date();
            var windowName = 'Print' + uniqueName.getTime();
            var printWindow = window.open(windowUrl, windowName, 'left=5000,top=5000,width=0,height=0');
            printWindow.document.write(printDiv);
            printWindow.document.close();
            printWindow.focus();
            printWindow.print();
            printWindow.close();
            return false;
        }      

       
    </script>
    
</head>
<body>
    <form id="form1" runat="server">
    <ajax:ToolkitScriptManager ID="tc1" runat="server"></ajax:ToolkitScriptManager>
     <asp:HiddenField ID="hidFinyear" runat="server" />
    <div class="divmain">
        <acc:Heading ID="pagehead" runat="server" HeadingText="Debit Note" />
    </div>
    <table style="width:100%; margin-left:2%">
    <tr>
    <td>
    <asp:HyperLink ID="hpr" runat="server" Text="Change Date" NavigateUrl="#"></asp:HyperLink>
    &nbsp;<asp:HyperLink ID="hpr1" runat="server" Text="Print" onClick="return printPartOfPage();" NavigateUrl="#"></asp:HyperLink>
    </td>
    </tr>
    </table>
    
    <div id="divPrint" class="divmain">
    <table style="width:98%; margin-left:2%">
    <tr>
    <td>
    <center><asp:Label ID="lblcompname" Font-Bold="true" Font-Size="Small" runat="server" ></asp:Label></center>
    </td>
    </tr>
    <tr>
    <td> <center><asp:Label ID="lblheading" runat="server" ></asp:Label></center></td>
    </tr>
    <tr  >
    <td><asp:GridView ID="grdDisplay" ShowFooter="true" OnRowDataBound="rowDataBound"  CssClass="gridview" runat="server" AutoGenerateColumns="false" Width="96%">
    <Columns>
    <asp:BoundField HeaderText="Date" DataField="TransactionDate" DataFormatString="{0:dd-MMM-yyyy}"/>
    <asp:BoundField HeaderText="Type" DataField="Name" />
    <asp:BoundField HeaderText="Voucher No." DataField="TransactionNumber" />
    <asp:BoundField HeaderText="Particulars" DataField="Particulars" />
    <asp:BoundField HeaderText="Debit" DataField="Debit"  ItemStyle-HorizontalAlign="Right"/>
    <asp:BoundField HeaderText="credit" DataField="Credit" ItemStyle-HorizontalAlign="Right" />
    </Columns>
    </asp:GridView> </td>
    </tr>
    </table>
        
    </div> 
  
    <asp:Panel ID="panel" CssClass="modalPopup" style= "display:none;" runat="server" Width="250px" Height= "140px" >
    <table style="width:60%; margin-left:50px; margin-top:20px;">
    <tr style="width:10%;" align="left">
    <td>From:</td>
    <td><asp:TextBox ID="txtFromDate" CssClass="input" Width="100px" runat="server" ></asp:TextBox></td>
    </tr>
    <tr style="width:10%;" >
    <td>To:</td>
    <td><asp:TextBox ID="txtToDate" CssClass="input" Width="100px" runat="server"></asp:TextBox></td>
    </tr>
    <tr>
    <td style="width:30%;" colspan="2">
     <center><asp:Button ID="btnShow" OnClientClick="return Validation();" CssClass=" button" Text="Show" runat="server" />
    <asp:Button ID="btnCancel" runat="server" Text="Cancel"   CssClass=" button" /></center>
    </td>
    </tr>
    </table>
    </asp:Panel>
    
    <ajax:ModalPopupExtender id="modalpopup" BackgroundCssClass="modalBackground"   runat="server" PopupControlID="panel" TargetControlID="hpr" CancelControlID="btnCancel">
    </ajax:ModalPopupExtender>
    </form>
</body>
</html>
